<?php
/*
    Copyright (C) 2008 - 2010 Inanta Martsanto
    
    This file is part of Koma.

    Koma is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Koma is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Koma.  If not, see <http://www.gnu.org/licenses/>.
    
    Inanta Martsanto (inanta@inationsoft.com)
*/
 
class KomaSession extends KomaSingletonObject
{
    function set($key, $value)
    {
        $_SESSION[$key] = $value;
    }
    
    function get($key)
    {
        return $_SESSION[$key];
    }
    
    function flush($key)
    {
        if(!isset($_SESSION[$key])) return false;
        
        $ret = $_SESSION[$key];
        unset($_SESSION[$key]);
        
        return $ret;
    }
    
    function fetchParams($method = 'p')
    {
        $params = array();
        
        switch($method)
        {
            case 'post':
            case 'p':
                $params = $_POST;
            case 'get':
            case 'g':
                $params = $_GET;
            case 'request':
            case 'r':
            default:
                $params = $_REQUEST;
        }

        foreach($params as $key => $param)
        {
            $_SESSION[$key] = $param;
        }
    }
    
    static function getInstance()
    {
        return self::createInstance(__CLASS__);
    }
}
?>